<?php
class Hospital extends ORDataObject{
	var $hospital_id	=	'';
	var $vi_name			=	'';
	var $en_name           =   '';
	
	var $_table			=	'hospital';
	var $_key			=	'hospital_id';
	var $_internalName	=	'Hospital';
	
	public function Hospital($db = null){
		parent::ORDataObject($db);
	}
	
	public function setup($id = 0){
		$this->set('id',$id);
		if($id > 0){
			$this->populate();
		}
	}
	
	public function populate(){
		parent::populate(true);
	}
	
	public function setData($name){
		$data	=	array(
			'name'	=>	$name
		);
		$this->populateArray($data);
	}
	
	public function getId(){
		return $this->hospital_id;
	}
	
    public function getIdFromName($name){
        $field  =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        $ds     =   & new   Datasource_sql();
        $sql    =   array(
            'cols'      =>  'hospital_id as id',
            'from'      =>  "$this->_table",
            'where'     =>  "$field='$name'",
            'orderby'   =>  'id'
        );
        $ds->setup($this->_db, $sql);
        $res    =   $ds->toArray('id');
        if(!empty($res))
            return $res[0];
        return 0;
    }
	
	public function getHospitalsByName($name) {
		$field		=	L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		$ds		=	 new	Datasource_sql();
		$sql	=	array(
			'cols'		=>	"hospital_id, $field hospital_name",
			'from'		=>	"$this->_table",
			'where'		=>	"$field like '%$name%'",
			'orderby'	=>	"$field"
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
}
?>